<!doctype html>
<html>
    <head>
        <title>填写注册地</title>
    
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
        <link rel="stylesheet" href="layui.css" media="all">
        <script src="layui.js"></script>
        <script src="jquery.1.12.4.js"></script>
        <link href="qiye.css" rel="stylesheet" />
        <style>
            #zhuce{
                width: 100%;
                height: 42px;
                display: flex;
                justify-content: left;
                flex-wrap: wrap;
                box-shadow: 0 1px 5px #ccc;
                border: 1px solid #fff;
            }
        </style>
    </head>
    <body>
		<div id="black"></div>
		<div id="error">
            <div class="errorImg"><img src="error.png" width="180" height="140" /></div>
            <div class="errorTitle">失败，请选择人员入组！</div>
            <div class="errorBtn">
                <span onlick="Close()">点击关闭</span>
            </div>
		</div>
        <div class="layui-form layBox">
            <dl class="dl">
                <dt>注册地：</dt>
                <dd>
                    <select id="zhuce" style="display: block;">
                        <option value="1">安平镇</option>
                        <option value="2">马店镇</option>
                        <option value="3">南王庄镇</option>
                        <option value="4">子文镇</option>
                        <option value="5">东黄城镇</option>
                        <option value="6">何庄乡</option>
                        <option value="7">油子乡</option>
                        <option value="8">两洼乡</option>
                        <option value="9">高新区</option>
                    </select>
                </dd>
            </dl>
            <div class="layui-btn onButton" _key="0">提交</div>
        </div>
        <div class="copy">
            <p><img src="http://qiye.city1000.cn/library/images/tishi.png" width="300" /></p>
            <p style="font-size: 18px;">安平县工业和信息化局</p>
            <p>技术支持：智慧安平</p>
        </div>

        <script>
            layui.use(['layer'], function(){
                var layer = layui.layer, //弹层
                form = layui.form;
            });

            /*函数 start*/
            // 获取URL里的参数函数
            function getQueryString(name){
                var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if(r!=null)return  unescape(r[2]); return null;
            }
            function Tanchuang (str, btnStr, num) {
                var black = $("#black");
                var box = $("#error");
                $(".errorTitle").html(str);
                if(num == 1){
                    // 关闭窗口
                    $(".errorBtn").html("<div class='baifenbai closeError'>"+btnStr+"</div>");
                    $(".closeError").click(function(){
                        var black = $("#black");
                        var box = $("#error");
                        black.fadeOut(500);
                        box.fadeOut(500);
                    });
                }
                if(num == 2){
                    // 跳转链接
                    $(".errorBtn").html("<div class='baifenbai linkUrl'>"+btnStr+"</div>");
                    $(".linkUrl").click(function(){
                        $(location).attr('href', 'http://qiye.city1000.cn/api/reg');
                    });
                }
                if(num == 3){
                    // 跳转链接
                    $(".errorBtn").html("<div class='baifenbai linkUrl'>"+btnStr+"</div>");
                    $(".linkUrl").click(function(){
                        $(location).attr('href', 'http://qiye.city1000.cn/api/reg');
                    });
                }
                
                black.fadeIn(500);
                box.fadeIn(500);
            }
            /*函数 end*/
            var code = getQueryString("code");
        
            if(code == "" || code == undefined || code == null){
                Tanchuang('网络繁忙', '点击重试', 2)
            }
        
            var url = "http://qiye.city1000.cn";

            var btn = $(".onButton");
            btn.unbind('click');
            btn.click(function(){
                var ts = $(this);
                var cId = $("#zhuce").val();

                var key = ts.attr("_key");
                if(key == 0){
                    ts.attr("_key", 1)
                    $.ajax({
                        url: url+"/api/update/qiye/post",
                        type: "POST",
                        data:{
                            "cId": cId,
                            "code": code
                        },
                        dataType: "json",	//数据格式，如果后台输出为非json，则会报错，可不填
                        success: function(data){
                            console.log(data);
                            if(data.code == 200){
                                layer.msg(data.msg);
                                setTimeout(function(){
                                    $(location).attr('href', "http://qiye.city1000.cn");
                                }, 1500);
                            }
                            if(data.code == 405){
                                Tanchuang(data.msg, '点击前往登记', 3)
                            }
                        },
                        error:function(XMLHttpRequest,textStatus,errorThrown){
                            ts.attr("_key", 0);
                            if(XMLHttpRequest.status!=200){
                                //状态码不为200，均为出错
                            };
                        }
                    });
                }
            });
        
           
        </script>
    </body>
</html>